using System.Collections.Generic;

public class GK_Leaderboard
{
	public GK_ScoreCollection SocsialCollection = new GK_ScoreCollection();

	public GK_ScoreCollection GlobalCollection = new GK_ScoreCollection();

	public Dictionary<string, int> currentPlayerRank = new Dictionary<string, int>();

	private GK_LeaderBoardInfo _info;

	public string id
	{
		get
		{
			return _info.Identifier;
		}
	}

	public GK_LeaderBoardInfo Info
	{
		get
		{
			return _info;
		}
	}

	public GK_Leaderboard(string leaderboardId)
	{
		_info = new GK_LeaderBoardInfo();
		_info.Identifier = leaderboardId;
	}

	public void UpdateMaxRange(int MR)
	{
		_info.MaxRange = MR;
	}

	public GK_Score GetCurrentPlayerScore(GK_TimeSpan timeSpan, GK_CollectionType collection)
	{
		string key = timeSpan.ToString() + "_" + collection;
		if (currentPlayerRank.ContainsKey(key))
		{
			int rank = currentPlayerRank[key];
			return GetScore(rank, timeSpan, collection);
		}
		return null;
	}

	public void UpdateCurrentPlayerRank(int rank, GK_TimeSpan timeSpan, GK_CollectionType collection)
	{
		string key = timeSpan.ToString() + "_" + collection;
		if (currentPlayerRank.ContainsKey(key))
		{
			currentPlayerRank[key] = rank;
		}
		else
		{
			currentPlayerRank.Add(key, rank);
		}
	}

	public GK_Score GetScore(int rank, GK_TimeSpan scope, GK_CollectionType collection)
	{
		GK_ScoreCollection gK_ScoreCollection = GlobalCollection;
		switch (collection)
		{
		case GK_CollectionType.GLOBAL:
			gK_ScoreCollection = GlobalCollection;
			break;
		case GK_CollectionType.FRIENDS:
			gK_ScoreCollection = SocsialCollection;
			break;
		}
		Dictionary<int, GK_Score> dictionary = gK_ScoreCollection.AllTimeScores;
		switch (scope)
		{
		case GK_TimeSpan.ALL_TIME:
			dictionary = gK_ScoreCollection.AllTimeScores;
			break;
		case GK_TimeSpan.TODAY:
			dictionary = gK_ScoreCollection.TodayScores;
			break;
		case GK_TimeSpan.WEEK:
			dictionary = gK_ScoreCollection.WeekScores;
			break;
		}
		if (dictionary.ContainsKey(rank))
		{
			return dictionary[rank];
		}
		return null;
	}

	public void UpdateScore(GK_Score s)
	{
		GK_ScoreCollection gK_ScoreCollection = GlobalCollection;
		switch (s.collection)
		{
		case GK_CollectionType.GLOBAL:
			gK_ScoreCollection = GlobalCollection;
			break;
		case GK_CollectionType.FRIENDS:
			gK_ScoreCollection = SocsialCollection;
			break;
		}
		Dictionary<int, GK_Score> dictionary = gK_ScoreCollection.AllTimeScores;
		switch (s.timeSpan)
		{
		case GK_TimeSpan.ALL_TIME:
			dictionary = gK_ScoreCollection.AllTimeScores;
			break;
		case GK_TimeSpan.TODAY:
			dictionary = gK_ScoreCollection.TodayScores;
			break;
		case GK_TimeSpan.WEEK:
			dictionary = gK_ScoreCollection.WeekScores;
			break;
		}
		if (dictionary.ContainsKey(s.GetRank()))
		{
			dictionary[s.GetRank()] = s;
		}
		else
		{
			dictionary.Add(s.GetRank(), s);
		}
	}
}
